<?php

namespace App\Http\Controllers\Manage;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

use App\Model\Demand;

class DemandController extends Controller
{
    /**
     * 需求列表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function demandList() {
        $demand = Demand::orderBy('rank','decs')->get();
        return view('manage.demand.demandList',['demand'=>$demand]);
    }

    /**
     *需求启禁用
     * @return array
     */
    public function demandStatus() {
        $id = Input::get('id');
        $status = Input::get('status');
        if($status == 1) {
            $del = Demand::where('id',$id)->update(['status'=>1]);
            $msg = '启用成功！';
        }else{
            $del = Demand::where('id',$id)->update(['status'=>0]);
            $msg = '禁用成功！';
        }
        if(!$del){
            return [
                'code'=>101,
                'msg'=>'设置失败！'
            ];
        }
        return [
            'code'=>100,
            'msg'=>$msg
        ];
    }

}
